package org.deri.socializer.com.xmpp;

public class XmppUser {

	private String host;
	private String resource;
	private String user;
	private String password;
	
	public XmppUser(String host, String user) {
		this.host 		= host;
		this.resource 	= "";
		this.user 		= user;
		this.password	= "";
	}
	
	public XmppUser(String host, String user, String password) {
		this.host 		= host;
		this.resource 	= "";
		this.user 		= user;
		this.password	= password;
	}
	
	public XmppUser(String host, String resource, String user, String password) {
		this.host 		= host;
		this.resource 	= resource;
		this.user		= user;
		this.password 	= password;
	}

	public String getUser() {
		return user;
	}

	public String getPassword() {
		return password;
	}
	
	
	
	public String getHost() {
		return host;
	}

	public String getResource() {
		return resource;
	}

	public String getJID() {
		if (this.resource != "") 
			return this.user + "@" + this.host + "/" + this.resource;
		else
			return this.user + "@" + this.host;
	}
	
	@Override
	public boolean equals(Object obj) {
		if (obj == null) return false;
		if (this == obj) return true;
		if (!(obj instanceof XmppUser)) return false;
		
		XmppUser xmppUser = (XmppUser)obj;
		
		return (this.getHost().equalsIgnoreCase(xmppUser.getHost())) &&
		       (this.getUser().equalsIgnoreCase(xmppUser.getUser()));
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((this.getHost() == null) ? 0 : this.getHost().hashCode());
		result = prime * result + ((this.getUser() == null) ? 0 : this.getUser().hashCode());
		return result;
	}
}
